unit MainFrm;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, jpeg, ExtCtrls;

type
  TMainForm = class(TForm)
    imgSrc: TImage;
    imgDest: TImage;

    cbOption: TComboBox;

    Label1: TLabel;
    Label2: TLabel;

    procedure FormCreate(Sender: TObject);
    procedure cbOptionChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation
uses Math;

{$R *.DFM}

procedure TMainForm.FormCreate(Sender: TObject);
begin
  cbOption.ItemIndex:=0;
end;

procedure TMainForm.cbOptionChange(Sender: TObject);
Type TPixelArr=Array[0..1000]of LongInt;
          PPixelArr=^TPixelArr;

var  p       :PPixelArr;
         x,y  :integer;
     R,G,B,gray:LongInt;


begin
 ImgDest.Picture:=ImgSrc.Picture;

 With ImgDest.Picture do begin

    Bitmap.PixelFormat:=pf32bit;
      for y:=0 to bitmap.height-1 do begin
        P:=bitmap.ScanLine[y];
        for x:=0 to Bitmap.Width-1 do
            case cbOption.ItemIndex of
              0:;
              1:P[x]:=P[x] xor $FFFFFF;
              2:P[x]:=P[x] and $0000FF;

              3:begin
                   R:=(P[x] shr 16) and $FF;
                   G:=(P[x] shr 8) and $FF;
                   B:=P[x] and $FF;
                   gray:=Max(R,Max(G,B));
                   p[x]:=(gray shl 16) or (gray shl 8) or gray;
                end;

              4:if (x mod 2)=0 then p[x]:=$FFFFFF;
            end;
    end;
 end;
end;
end.
